package Controllers::Actions;

use lib 'd:/test_project/application/';
#use Conf;
use Views::Helpers::CSS;
use Views::Helpers::JS;
use Views::Helpers::Meta;

use Models::ContentModel;
use Models::MenuModel;

use Data::Dumper;
use warnings;

use DBI;

use strict;

my $scripts = Views::Helpers::JS->new;
my $css = Views::Helpers::CSS->new;
my $meta = Views::Helpers::Meta->new;
my $title = "no title";
my $url = undef;
my @menu;
my $action;
my $tpl;

BEGIN {
	my $menu = Models::MenuModel->new;
	@menu =  $menu->getFullMenu();
}


sub pageAction {
	$action = shift;
	
	$tpl = (-e "d:/test_project/lib/Views/Templates/$action.htm") ? $action : "page";

	$meta->setTitle('InterLogic. ');
	$meta->setKeywords('InterLogic','Web developing', '.NET', 'Java', 'PHP', 'PERL', 'ActionScript', 'Ukrainian developer', 'Danish developer');
	$meta->setDescription('InterLogic - a Ukrainian-Danish company that has been creating software. ');
	$css->addFiles('main.css');


	my $content = Models::ContentModel->new;
	$content = $content->filterByCode($action)->findOne();

	$meta->addTitle($content->getMetaTitle());
	$meta->addDescription($content->getMetaDescription());
	$meta->addKeywords($content->getMetaKeywords());
	$title = $content->getTitle();

       # print "Content-type: text/html\n\n", Dumper $content;

	{
		'title' => $title,
		'css' => $css->getFiles() . $css->getStyle(),
		'scripts' => $scripts->getFiles() . $scripts->getScript(),
		'action' => $action,
		'maintpl' => $tpl,
		'meta' => $meta->getValues(),
		'pagetext' => $content->getText(),
		'menu' => \@menu
	};
}

sub homeAction{
	$action = substr((caller(0))[3], 22,-6);
	$tpl = (-e "d:/test_project/lib/Views/Templates/$action.htm") ? $action : "page";

	$meta->setTitle('InterLogic. ');
	$meta->setKeywords('InterLogic','Web developing', '.NET', 'Java', 'PHP', 'PERL', 'ActionScript', 'Ukrainian developer', 'Danish developer');
	$meta->setDescription('InterLogic - a Ukrainian-Danish company that has been creating software. ');
	$scripts->addFiles('jquery-1.8.0.min.js','jquery-ui-1.8.23.custom.min.js');
	# $scripts->setScript('
		 # $(function() {
			 # $( "#tabs" ).tabs();
		 # });
	# ');
	$css->addFiles('blitzer/jquery-ui-1.8.23.custom.css','main.css');

	my $content = Models::ContentModel->new;
	$content = $content->filterByCode('home')->findOne();

	$meta->addTitle($content->getMetaTitle());
	$meta->addDescription($content->getMetaDescription());
	$meta->addKeywords($content->getMetaKeywords());
	$title = $content->getTitle();

	{
		'title' => $title,
		'css' => $css->getFiles() . $css->getStyle(),
		'scripts' => $scripts->getFiles() . $scripts->getScript(),
		'action' => $action,
		'maintpl' => $tpl,
		'meta' => $meta->getValues(),
		'pagetext' => $content->getText(),
		'menu' => \@menu
	};
}


1;